﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Random_Password
{
     class Random_Password
    {

        int Upper_len;
        int Lower_len;
        int Digit_len;
        int Symbol_len;
        static string Upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        static string Lower = "abcdefghijklmnopqrstuvwxyz";
        static string Digit = "1234567890";
        static string Symbol = "~!@#$%^&*()_+{}|:\"<>?`[]\\;\',./";
        public Random_Password()
        {
            this.Upper_len = 0;
            this.Lower_len = 4;
            this.Digit_len = 4;
            this.Symbol_len = 4;
        }

        //设置属性，取各个种子的数量
        public int Set_Upper_len
        {
            set { Upper_len = value; }
            get { return Upper_len; }
        }
        public int Set_Lower_len
        {
            set { Lower_len = value; }
            get { return Lower_len; }
        }
        public int Set_Digit_len
        {
            set { Digit_len = value; }
            get { return Digit_len; }
        }
        public int Set_Symbol_len
        {
            set { Symbol_len = value; }
            get { return Symbol_len; }
        }
        public string Get_Ran_string
        {
            get
            {
                return Final_str();
                
            }
        }
        //重组筛选过的种子字符串
        string Final_str()
        {
            string Ran_string = "";
            string final_string = "";
            string source = Make_ran_str(Upper, Upper_len) + Make_ran_str(Lower, Lower_len) + Make_ran_str(Digit, Digit_len) + Make_ran_str(Symbol, Symbol_len);
            while (source.Length != 0)
            {
                Random x = new Random();
                int y = x.Next(0, source.Length);
                Ran_string = Ran_string + source[y];
                source = source.Remove(y, 1);
                Thread.Sleep(20);
            }
            while (Ran_string.Length != 0)
            {
                Random x = new Random();
                int y = x.Next(0, Ran_string.Length);
                final_string = final_string + Ran_string[y];
                Ran_string = Ran_string.Remove(y, 1);
                Thread.Sleep(20);
            }

            return final_string;
        }
        //筛选种子字符串
        private static string Make_ran_str(string str_seed, int Ran_str_len)
        {
            string Ret_str = "";
            Random ran = new Random();
            int i = 0;
            while (i < Ran_str_len)
            {
                Ret_str = Ret_str + str_seed[ran.Next(0, str_seed.Length)];
                i++;
            }
            return Ret_str;
        }



    }
}
